package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DictionaryItem;
import cn.wolfcode.crm.query.DictionaryItemQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("systemDictionaryItem")
public class DictionaryItemController {
    @Autowired
    private IDictionaryItemService dictionaryItemService;

    @RequiresPermissions(value={"systemDictionaryItem:getItemBySn","系统字典明细列表"},logical = Logical.OR)
    @RequestMapping("getItemBySn")
    @ResponseBody
    public PageResult query(DictionaryItemQueryObject qo) {
        return dictionaryItemService.query(qo);
    }

    @RequiresPermissions(value={"dictionaryItem:saveOrUpdate","系统字典明细编辑/新增"},logical = Logical.OR)
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(DictionaryItem entity) {
        try {
            dictionaryItemService.saveOrUpdate(entity);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }
    @RequiresPermissions(value={"dictionaryItem:delete","系统字典明细删除"},logical = Logical.OR)
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        try {
            dictionaryItemService.deleteByPrimaryKey(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark("操作失败!原因:" + e.getMessage());
        }
    }

}
